	    //查询
	    //同时删多条
		var url;
		function add(){ //打开一个对话框
			$('#dlg').dialog('open').dialog('center').dialog('setTitle','New');
			$('#form1').form('clear');
			url = 'user/add';
		}
		
		function edit(){
			var row = $('#dg').datagrid('getSelected');
			if (row){
				$('#dlg').dialog('open').dialog('center').dialog('setTitle','Edit');
				$('#form1').form('load',row);
				url = 'user/edit';
			}
		}

		function save(){  //弹出框共用  同是一个Save提交按钮  add,edit
			if(!$("#form1").form('validate')) return;
			var data = $("#form1").serialize();     
			   $.ajax({ 
			    type:'post',  
			    url:url, 
			    data:data,  
			    dataType:'json', 
			    
			   success: function(result){
				if (result.errorMsg){
					$.messager.show({
						title: 'Error',
						msg: result.errorMsg
					});
				} else {
					$('#dlg').dialog('close');
					$('#dg').datagrid('reload');
				}
			}
		});
		}
		
		function del(){
// 			var row = $('#dg').datagrid('getSelected');
			var row=$("#dg").datagrid("getSelections");
			if (row){
				$.messager.confirm('Confirm','Are you sure delete the record(s)?',function(r){
					if (r){
						var ids;
						for(var i=0;i<row.length;i++){
							if(i==0){
								ids=(row[i].id);
							}else{
								ids+=","+row[i].id;
							}
						}
						$.post('user/del',{ids:ids},function(result){
							if (result.errorMsg){
								$.messager.show({	// show error message
									title: 'Error',
									msg: result.errorMsg
								});
							}else{
								$('#dg').datagrid('reload');
								$.messager.show({
									title: 'delete',
									msg: 'delete successfully'
								});	
							}
						},'json'); //json格式?
					}
				});
			}
		}
		
		function find(){
           var page=1;
           var pageSize=$("#dg").datagrid("getPager").data("pagination").options.pageSize;
           
   		var data={};
		if($('#userid').val()!=""){
			data.userid=$('#userid').val();
		}
		if($('#email').val()!=""){
			data.email=$('#email').val();
		}
 			$.post('user/list?page='+page+'&rows='+pageSize,data,
			     function(result){
				      if (result){
	                    //将搜索结果显示在当前页面
	                    $("#dg").datagrid("loadData", result.rows);
	                    $("#dg").datagrid("getPager").pagination('refresh', {
	                        total: result.total
	                    });
	                }
			},'json'); 
		}
		
		
 		$(function(){
		 //获取页面分页对象
	    var p = $('#dg').datagrid('getPager');
	    if (p){
	           $(p).pagination({
	             onSelectPage:function (page,pageSize) {
	        		var data={};
	        		if($('#userid').val()!=""){
	        			data.userid=$('#userid').val();
	        		}
	        		if($('#email').val()!=""){
	        			data.email=$('#email').val();
	        		}
	        		
	      			$.post('user/list?page='+page+'&rows='+pageSize,data,
	      				     function(result){
	      					      if (result){
// 	      		                    $("#dg").datagrid("loadData", result.rows);  //可以
                                    $("#dg").datagrid("loadData", result);
	      		                    $("#dg").datagrid("getPager").pagination('refresh', {
	      		                        total: result.total
	      	 	                        ,
	      	 	                        pageNumber : page
	      		                    });
	      		                }
	      				},'json'); 
	              } 
	           });
	     }
	 });
 		
 		
 function turnPage(rest){
	 
	    var p = $('#dg').datagrid('getPager');
	    if (p){
	           $(p).pagination({
	             onSelectPage:function (page,pageSize) {

	             	   var data = $("#formSearch").serializeFilterNull();
//                   alert("--paing---"+data);
	        		
	      			$.post(rootpath+'/'+rest+'/list?page='+page+'&rows='+pageSize,data,
	      				     function(result){
	      					      if (result){
// 	      		                    $("#dg").datagrid("loadData", result.rows);  //可以
                                    $("#dg").datagrid("loadData", result);
	      		                    $("#dg").datagrid("getPager").pagination('refresh', {
	      		                        total: result.total
	      	 	                        ,
	      	 	                        pageNumber : page
	      		                    });
	      		                }
	      				},'json'); 
	              } 
	           });
	     }
 }		
 		